<template>
  <el-dialog
    title="修改用户"
    :visible.sync="visible"
    :close-on-click-modal="false"
    top="8vh"
    width="30%"
  >
    <this-form ref="form" />
    <div slot="footer" class="">
      <el-button class="px-12" type="primary" @click="onSubmit"
        >确 定</el-button
      >
      <el-button class="px-12" plain @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import thisForm from "./form.vue";

export default {
  components: { thisForm },
  data() {
    return {
      visible: false,
      row: null,
    };
  },
  methods: {
    open(row) {
      this.row = row;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs.form.init(row);
      });
    },
    onSubmit() {
      this.$refs.form.validate((form) => {
        this.axios
          .post(`robot/save`, {
            ...form,
            targetId: this.row.cid,
            // userId: form.uid,
          })
          .then((res) => {
            if (res.retCode != 0) {
              return this.$message.error(res.retMsg);
            }
            this.$emit("added");
            this.$message.success("操作成功!");
            this.visible = false;
          });
      });
    },
  },
};
</script>

<style scoped>
</style>